﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Security.Principal;
using System.Threading;
using System.Windows.Forms;
using DevExpress.LookAndFeel;
using DevExpress.Xpo;

namespace Submitter
{
    static class Program
    {
        private static NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger();
        public static object CurrentUserId { get; set; }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.ThreadException += ApplicationOnThreadException;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            DevExpress.Skins.SkinManager.EnableFormSkins();
            DevExpress.UserSkins.BonusSkins.Register();
            UserLookAndFeel.Default.SetSkinStyle("VS2010");

            XpoDefault.ConnectionString =
                ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

            // DevExpress.Utils.AppearanceObject.DefaultFont = new Font("Tahoma", 20);

            Application.Run(new Form1());
        }

        private static void ApplicationOnThreadException(object sender, ThreadExceptionEventArgs threadExceptionEventArgs)
        {
            _logger.ErrorException("发生异常", threadExceptionEventArgs.Exception);
        }

        private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
        {
            var ex = unhandledExceptionEventArgs.ExceptionObject as Exception;
            if (ex != null)
            {
                _logger.ErrorException("发生异常", ex);
            }
        }
    }
}